home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 8 / IOPROG_8.ISO / soft / sdkplnet / mac / plgsk401.sit / PluginSDK 4.01a / Examples / CharFlipper / Source / CMacFlipView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-09  |  4.0 KB  |  144 lines

  1. #ifndef _NPAPI_H_
  2. #include "npapi.h"
  3. #endif
  4.  
  5. #include "CMacFlipView.h"
  6.  
  7. //======================================================================
  8. //        CMacFlipView::CMacFlipView()
  9. //======================================================================
  10.  
  11. CMacFlipView::CMacFlipView( CCharFlipper* inController )
  12. :    CFlipView( inController )
  13. {
  14.     mSavePort.clipRgn = ::NewRgn();
  15. }
  16.  
  17. //======================================================================
  18. //        CMacFlipView::~CMacFlipView()
  19. //======================================================================
  20. CMacFlipView::~CMacFlipView()
  21. {
  22.     if( mSavePort.clipRgn ) {
  23.         ::DisposeRgn(mSavePort.clipRgn);
  24.     }
  25. }
  26.  
  27. //---------------------------------------------------------
  28. // CMacFlipView::GetWindow
  29. //---------------------------------------------------------
  30. NPWindow*
  31. CMacFlipView::GetWindow()
  32. {
  33.     return mWindow;
  34. }
  35.  
  36. //======================================================================
  37. //        CMacFlipView::SetWindow
  38. //======================================================================
  39. NPError
  40. CMacFlipView::SetWindow( NPWindow* inWindow )
  41. {
  42.     mWindow = inWindow;
  43.     Paint();
  44.     return NPERR_NO_ERROR;
  45. };
  46.  
  47. //======================================================================
  48. //        CMacFlipView::Paint()
  49. //======================================================================
  50. void
  51. CMacFlipView::Paint()
  52. {
  53.     if( mWindow ) {
  54.         if( StartDraw( mWindow ) ) {
  55.             DoDraw( mCurrentChar, mWindow );
  56.             EndDraw( mWindow );
  57.         }
  58.     }
  59. }
  60.  
  61. //------------------------------------------------------------------------------------
  62. // CMacFlipView::StartDraw:
  63. //------------------------------------------------------------------------------------
  64. Boolean
  65. CMacFlipView::StartDraw(NPWindow* inWindow)
  66. {
  67.     if (inWindow == NULL)
  68.         return FALSE;
  69.     NP_Port* port = (NP_Port*) inWindow->window;
  70.     if (inWindow->clipRect.left < inWindow->clipRect.right)
  71.     {
  72.     // Preserve the old port
  73.         ::GetPort((GrafPtr*)&mOldPort);
  74.         ::SetPort((GrafPtr)port->port);
  75.     // Preserve the old drawing environment
  76.         mSavePort.portRect = port->port->portRect;
  77.         mSavePort.txFont = port->port->txFont;
  78.         mSavePort.txFace = port->port->txFace;
  79.         mSavePort.txMode = port->port->txMode;
  80.         mSavePort.rgbFgColor = port->port->rgbFgColor;
  81.         mSavePort.rgbBkColor = port->port->rgbBkColor;
  82.         ::GetClip(mSavePort.clipRgn);
  83.     // Setup our drawing environment
  84.         Rect clipRect;
  85.         clipRect.top = inWindow->clipRect.top + port->porty;
  86.         clipRect.left = inWindow->clipRect.left + port->portx;
  87.         clipRect.bottom = inWindow->clipRect.bottom + port->porty;
  88.         clipRect.right = inWindow->clipRect.right + port->portx;
  89.         ::SetOrigin(port->portx,port->porty);
  90.         ::ClipRect(&clipRect);
  91.         clipRect.top = clipRect.left = 0;
  92.         TextSize(inWindow->height);
  93.         TextFont(geneva);
  94.         TextMode(srcCopy);
  95.         RGBColor  col;
  96.         col.red = col.green = col.blue = 30000;
  97.         RGBForeColor(&col);
  98.         col.red = col.green = col.blue = 65000;
  99.         RGBBackColor(&col);
  100.         return TRUE;
  101.     }
  102.     else
  103.         return FALSE;
  104. }
  105.  
  106.  
  107. //------------------------------------------------------------------------------------
  108. // CMacFlipView::EndDraw:
  109. //------------------------------------------------------------------------------------
  110. void
  111. CMacFlipView::EndDraw(NPWindow* inWindow)
  112. {
  113.     NP_Port* port = (NP_Port*) inWindow->window;
  114.     ::SetOrigin(mSavePort.portRect.left, mSavePort.portRect.top);
  115.     ::SetClip(mSavePort.clipRgn);
  116.     CGrafPtr myPort;
  117.     ::GetPort((GrafPtr*)&myPort);
  118.     myPort->txFont = mSavePort.txFont;
  119.     myPort->txFace = mSavePort.txFace;
  120.     myPort->txMode = mSavePort.txMode;
  121.     ::RGBForeColor(&mSavePort.rgbFgColor);
  122.     ::RGBBackColor(&mSavePort.rgbBkColor);
  123.     ::SetPort((GrafPtr)mOldPort);
  124. }
  125.  
  126.  
  127. //------------------------------------------------------------------------------------
  128. // CMacFlipView::DoDraw:
  129. //------------------------------------------------------------------------------------
  130. void
  131. CMacFlipView::DoDraw( char inChar, NPWindow* inWindow )
  132. {
  133.         Rect drawRect;
  134.         drawRect.top = 0;
  135.         drawRect.left = 0;
  136.         drawRect.bottom = drawRect.top + inWindow->height;
  137.         drawRect.right = drawRect.left + inWindow->width;
  138.         ::EraseRect(&drawRect);
  139.     
  140.         MoveTo(drawRect.left, drawRect.bottom - 10);
  141.         ::DrawChar( inChar );
  142. }
  143.  
  144.